home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Documentary Synchronicity ƒ / Source ƒ / Support ƒ / AERequired.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-07  |  3.9 KB  |  153 lines  |  [TEXT/KAHL]

  1. /* 4567890123456789012345678901234567890123456789012345678901234567 */
  2. /*
  3.  * File:              AERequired.c
  4.  * Author:            Mark H. Linton
  5.  * Creation Date:     2/4/95
  6.  * Modification Date: 
  7.  * Description:       A set of routines which may be used to handle 
  8.  *                    the processing of the four required AppleEvents.
  9.  */
  10. #include <AppleEvents.h>
  11.  
  12. #include "AERequired.h"
  13. #include "main.h"
  14.  
  15. static Boolean GotAllParameters(AppleEvent *aMessage);
  16. static pascal OSErr HandleOAPP(AppleEvent *aMessage, 
  17.     AppleEvent *aReply, long aRefCon);
  18. static pascal OSErr HandleODOC(AppleEvent *aMessage, 
  19.     AppleEvent *aReply, long aRefCon);
  20. static pascal OSErr HandlePDOC(AppleEvent *aMessage, 
  21.     AppleEvent *aReply, long aRefCon);
  22. static pascal OSErr HandleQUIT(AppleEvent *aMessage, 
  23.     AppleEvent *aReply, long aRefCon);
  24.  
  25. pascal OSErr InstallRequiredAppleEvents(void) {
  26.     OSErr theError;
  27.     
  28.     theError = AEInstallEventHandler(kCoreEventClass, 
  29.         kAEOpenApplication, (AEEventHandlerUPP)&HandleOAPP, 0, false);
  30.     if (theError == noErr) {
  31.         theError = AEInstallEventHandler(kCoreEventClass, 
  32.             kAEOpenDocuments, (AEEventHandlerUPP)&HandleODOC, 0, false);
  33.     }
  34.     if (theError == noErr) {
  35.         theError = AEInstallEventHandler(kCoreEventClass, 
  36.             kAEPrintDocuments, (AEEventHandlerUPP)&HandlePDOC, 0, false);
  37.     }
  38.     if (theError == noErr) {
  39.         theError = AEInstallEventHandler(kCoreEventClass, 
  40.             kAEQuitApplication, (AEEventHandlerUPP)&HandleQUIT, 0, 
  41.             false);
  42.     }
  43.     return theError;
  44. }
  45.  
  46. pascal OSErr HandleOAPP(AppleEvent *aMessage, AppleEvent *aReply, 
  47.         long aRefCon) {
  48.     OSErr theError;
  49.     
  50.     if (GotAllParameters(aMessage)) {
  51.         theError = DoNewCommand();
  52.     } else {
  53.         theError = errAEParamMissed;
  54.     }
  55.     return theError;
  56. }
  57.  
  58. Boolean GotAllParameters(AppleEvent *aMessage) {
  59.     Boolean gotAllParameters;
  60.     DescType theType;
  61.     Size theSize;
  62.     OSErr theError;
  63.     
  64.     theError = AEGetAttributePtr(aMessage, keyMissedKeywordAttr, 
  65.         typeWildCard, &theType, nil, 0, &theSize);
  66.     if (theError == errAEDescNotFound) {
  67.         gotAllParameters = true;
  68.     } else {
  69.         gotAllParameters = false;
  70.     }
  71.     return gotAllParameters;
  72. }
  73.  
  74. pascal OSErr HandleODOC(AppleEvent *aMessage, AppleEvent *aReply, 
  75.         long aRefCon) {
  76.     OSErr theError;
  77.     AEDescList theDocuments;
  78.     long item, numItems;
  79.     AEKeyword theKeyword;
  80.     DescType theType;
  81.     FSSpec theFile;
  82.     Size theSize;
  83.     
  84.     theError = AEGetParamDesc(aMessage, keyDirectObject, typeAEList, 
  85.         &theDocuments);
  86.     if (theError == noErr) {
  87.         if (GotAllParameters(aMessage)) {
  88.             theError = AECountItems(&theDocuments, &numItems);
  89.             if (theError == noErr) {
  90.                 for (item = 1; item <= numItems; item++) {
  91.                     theError = AEGetNthPtr(&theDocuments, item, typeFSS,
  92.                         &theKeyword, &theType, &theFile, sizeof(FSSpec),
  93.                         &theSize);
  94.                     if (theError == noErr) {
  95.                         DoOpenCommand(&theFile);
  96.                     }
  97.                 }
  98.             }
  99.         } else {
  100.             (void)AEDisposeDesc(&theDocuments);
  101.             theError = errAEParamMissed;
  102.         }
  103.     }
  104.     return theError;
  105. }
  106.  
  107. pascal OSErr HandlePDOC(AppleEvent *aMessage, AppleEvent *aReply, 
  108.         long aRefCon) {
  109.     OSErr theError;
  110.     AEDescList theDocuments;
  111.     long item, numItems;
  112.     AEKeyword theKeyword;
  113.     DescType theType;
  114.     FSSpec theFile;
  115.     Size theSize;
  116.     
  117.     theError = AEGetParamDesc(aMessage, keyDirectObject, typeAEList, 
  118.         &theDocuments);
  119.     if (theError == noErr) {
  120.         if (GotAllParameters(aMessage)) {
  121.             theError = AECountItems(&theDocuments, &numItems);
  122.             if (theError == noErr) {
  123.                 for (item = 1; item <= numItems; item++) {
  124.                     theError = AEGetNthPtr(&theDocuments, item, typeFSS,
  125.                         &theKeyword, &theType, &theFile, sizeof(FSSpec),
  126.                         &theSize);
  127.                     if (theError == noErr) {
  128. #if 0
  129.                         DoPrintFile(theFile);
  130. #endif
  131.                     }
  132.                 }
  133.             }
  134.         } else {
  135.             (void)AEDisposeDesc(&theDocuments);
  136.             theError = errAEParamMissed;
  137.         }
  138.     }
  139.     return theError;
  140. }
  141.  
  142. pascal OSErr HandleQUIT(AppleEvent *aMessage, AppleEvent *aReply, 
  143.         long aRefCon) {
  144.     OSErr theError;
  145.     
  146.     if (GotAllParameters(aMessage)) {
  147.         theError = DoQuit();
  148.     } else {
  149.         theError = errAEParamMissed;
  150.     }
  151.     return theError;
  152. }
  153.